package com.hw.springcloud.controller;

import com.hw.springcloud.entities.CommonResult;
import com.hw.springcloud.entities.Payment;
import com.hw.springcloud.service.PaymentOpenFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname: OpenFeignController
 * @Description: OpenFeign控制层
 * @Date: 2021/8/16
 * @Author: huwei
 */
@RestController
@Slf4j
@RequestMapping("/order")
public class OpenFeignController {

    @Autowired
    private PaymentOpenFeignService paymentOpenFeignService;

    @GetMapping("/test")
    public String linkTest(){
        return "正常";
    }

    @GetMapping("/openfeign/getById/{id}")
    public CommonResult<Payment> getById(@PathVariable("id")Long id){
        return paymentOpenFeignService.getById(id);
    }

    /**
     * 测试链接超时
     *
     * 因为这里使用的负载均衡,但是只有一个服务上写了超时方法,所以当调用没有先超时方法的服务会报404错误
     *
     */
    @GetMapping("/openFeign/timeout")
    public String timeout(){
        log.info("发送调用超时接口请求");
        return paymentOpenFeignService.timeout();
    }
}
